package cn.edu.zafu.bigdata.liuwenyi;

import java.util.Collections;
import java.util.List;

public class GenericMaxFinder {

    public static <T extends Comparable<T>> T findMax(List<T> list){
        if(list == null || list.isEmpty()) {
            throw new IllegalArgumentException("列表不能为空");
        }
        return Collections.max(list);
    }

    public static void main(String[] args) {

        List<Integer> intList = List.of(11, 21, 10, 31, 4);
        Integer maxInt = findMax(intList);
        System.out.println("整数列表中的最大值是：" + maxInt);

        List<String> strList = List.of("sohee", "Lwy", "nova");
        String maxStr = findMax(strList);
        System.out.println("字符串列表中的最大值是：" + maxStr);
    }
}
